<template>
	<view style="width: 90%; margin: 0px auto;">
		<view class="">
			<uni-list>
				<uni-list-item @click="info(1)" clickable  title="头像更改"  showArrow note="">
					<template v-slot:footer>
						<view>
							<u-upload
									:fileList="fileList1"
									@afterRead="afterRead"
									@delete="deletePic"
									name="1"
									multiple
									:maxCount="10"
								></u-upload>
						</view>
					</template>
				</uni-list-item>
				<uni-list-item @click="info(2)" clickable  title="密码修改"  showArrow note=""></uni-list-item>
			</uni-list>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fileList1:[]
			}
		},
		methods: {
			deletePic(event) {
							this[`fileList${event.name}`].splice(event.index, 1)
						},
						// 新增图片
						async afterRead(event) {
							// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
							let lists = [].concat(event.file)
							let fileListLen = this[`fileList${event.name}`].length
							lists.map((item) => {
								this[`fileList${event.name}`].push({
									...item,
									status: 'uploading',
									message: '上传中'
								})
							})
							for (let i = 0; i < lists.length; i++) {
								const result = await this.uploadFilePromise(lists[i].url)
								let item = this[`fileList${event.name}`][fileListLen]
								this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
									status: 'success',
									message: '',
									url: result
								}))
								fileListLen++
							}
						},
						uploadFilePromise(url) {
							return new Promise((resolve, reject) => {
								let a = uni.uploadFile({
									url: 'http://127.0.0.1:8081/imgUpDown', // 仅为示例，非真实的接口地址
									filePath: url,
									name: 'file',
									formData: {
										id:uni.getStorageSync('user_id')
									},
									success: (res) => {
										setTimeout(() => {
											uni.showToast({
												icon:"success",
												title:"修改图片成功"
											})
											resolve(res.data.data)
										}, 1000)
									}
								});
							})
						},
				
			info(index){
				switch(index){
					case 2:uni.navigateTo({	
						url:"/pages/my/password"
					})
				}
			},
			
		}
	}
</script>

<style>

</style>
